<?php
namespace Crm\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Expression;

class MealorderTable extends AbstractTable
{

    protected $table = 'hy_mealorder';

    protected $id = 'id';
    
    public function find()
    {
        $rowset = $this->select();
        $result = $rowset->toArray();
        return $result;
    }

    public function findAll()
    {
        $rowset = $this->select();
        $result = $rowset->toArray();
        return $result;
    }

    public function findOne($id)
    {
        $rowset = $this->select(array(
            'id' => $id
        ));
        $row = $rowset->current();
        return $row;
    }

    public function findAllByDataAndType($type, $sell_data, $admin_org_id)
    {

        $select = new Select(array(
            'm' => $this->getTable()
        ));
        // $select->columns(array(''));
        $select->join(array(
            'p' => 'hy_product'
        ), 'p.product_id=m.product_id', array(
            'product_name'
        ), $select::JOIN_LEFT);

        $select->where(array(
                'm.type' => $type, 'm.'.$sell_data => 1
        ));
        
        $select->where(array(
            'p.org_id' => $admin_org_id
        ));

        $rowset = $this->selectWith($select);
        //return $rowset->getDataSource();
        $result = $rowset->toArray();
        return $result;
        
 
    }
    
    public function create($data)
    {
        return $this->insert($data);
    }

    public function updateById()
    {}

    public function remove($where)
    {
        if(is_array($where) && !empty($where)){
            return $this->delete($where);
        }else {
            return;
        }
        
    }

}